<template>
  <div class="my-tab-panel bg-white">
    <div class="my-tabs-list-wrapper">
      <ul class="my-tabs-list">
        <AmyPageTab
          v-for="tab in tabs"
          :tab-data="tab"
          @tab-close="closeTab(tab)"
          :key="tab.path"
          @click="clickTab(tab)"
        ></AmyPageTab>
      </ul>
    </div>
  </div>
</template>

<script lang="ts">

import AmyPageTab from './AmyPageTab.vue';
import { defineComponent, toRefs } from 'vue';
import { useRouter } from 'vue-router';
import { menuTab } from 'stores/model';
import { useNavTabStore } from 'stores/navTabStore';
import { isObjectEmpty } from 'src/util/utils';

export default defineComponent({
  name: 'AmyPageTabPanels',
  components: {
    AmyPageTab
  },
  props: {
    tabs: {
      type: Array,
      required: true
    }
  },
  setup (props, context) {
    const {
      tabs
    } = toRefs(props);

    //路由
    let router = useRouter();
    let navStore = useNavTabStore();

    //点击tab面板
    const clickTab = (tab: menuTab) => {
      router.push(`${tab.path}`);  //`${ }`模版字符串
    }

    //关闭tab面板
    const closeTab = (tab: menuTab) => {
      let menu = navStore.getNextRouteTabs(tab);
      navStore.removeRouteTabs(tab);
      if (!isObjectEmpty(menu)) {
        router.push(menu.path);
      }
    }
    return {
      tabs,
      clickTab,
      closeTab
    }
  }
})
</script>

<style lang="scss" scoped>
.my-tab-panel {
  position: relative;
}
.my-tabs-list-wrapper{
  padding: 0px 8px;
}
@keyframes loading-rotate {
  from {
    transform: rotate(0);
  }

  to {
    transform: rotate(360deg);
  }
}

@keyframes loading-rotate {
  from {
    transform: rotate(0);
  }

  to {
    transform: rotate(360deg);
  }
}

.my-tabs-list {
  list-style: none;
  margin: 0px;
  padding: 0px;
  overflow: auto;
  width: auto;
  zoom: 1;

  >li {
    float: left;
    margin: 2px;
    padding: 5px 10px ;
    position: relative;
    color: #242323;

    &.loading:before {
      content: ' ';
      box-sizing: border-box;
      display: inline-block;
      width: 14px;
      height: 14px;
      position: absolute;
      left: 0px;
      top: 10px;
      border-radius: 9px;
      border: 2px solid #1ab394;
      border-top-color: transparent;
      border-left-color: transparent;
      animation: loading-rotate 0.8s infinite linear;
      -webkit-animation: loading-rotate 0.8s infinite linear;
    }

    &.active {
      color: #333;

      &:after {
        content: ' ';
        position: absolute;
        bottom: 0px;
        width: 100%;
        height: 2px;
        background-color: #1ab394;
        left: 0px;
      }

      .my-btn-close {
        opacity: 1;
      }
    }

    &:hover {
      cursor: pointer;
      background-color: $green-2;
      .my-btn-close {
        opacity: 1;
      }
    }

    .my-btn-close {
      position: absolute;
      display: inline-block;
      opacity: 0;
      top: 6px;
      right: 0px;
      line-height: 12px;
      width: 14px;
      height: 14px;
      border-radius: 14px;
      font-size: 12px;
      color: #999;
      transition: all 0.2s ease;

      &:hover {
        color: $orange-2;
        transform: scale(1.5);
        cursor: pointer;
      }
    }
  }
}

</style>
